<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content-home="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<meta property="qc:admins" content="132223467642714633" />
		<title>Homeless</title>

		<link rel="stylesheet" type="text/css" href="__CSS__/index.css" />
		<link rel="stylesheet" type="text/css" href="__CSS__/prompt.css" />

		<script type="text/javascript" src="http://cdn.hcharts.cn/jquery/jquery-2.1.4.min.js"></script>
		<script src="__JS__/ip.js" type="text/javascript" charset="utf-8"></script>
		<script src="__JS__/prompt.js" type="text/javascript" charset="utf-8"></script>
		<script src="__JS__/public.js" type="text/javascript" charset="utf-8"></script>
		<script></script>

	</head>

	<body>
		<!--
        	作者：cs-windroid@qq.com
        	时间：2016-06-27
        	描述：banner
        -->
		<div id="banner">
			<div id="home" class="toggle selected">
				主页
			</div>
			<div id="text" class="toggle">
				文章
			</div>
			<div id="music" class="toggle"  style="display: none;">
				音乐
			</div>
			<div id="pool" class="toggle" style="display: none;">
				树洞
			</div>
			<div id="user">
				<img/>
				<div id="nickname">
				</div>
			</div>
		</div>
		<!--
        	作者：cs-windroid@qq.com
        	时间：2016-06-27
        	描述：home
        -->
		<div id="content-home" class="content">
			<div id="img"></div>
			<div id="imgauthor"></div>
			<div id="words"></div>
			<div id="copyright"><a href="http://wufazhuce.com/" target="_blank">© 「ONE · 一个」</a></div>
		</div>
		<!--
        	作者：cs-windroid@qq.com
        	时间：2016-06-27
        	描述：text
        -->
		<div id="content-text" class="content" style="display: none;">
			<iframe frameborder="no" border="0" width="100%" height="98%"></iframe>
		</div>
		<!--
        	作者：cs-windroid@qq.com
        	时间：2016-06-27
        	描述：user collection
        -->
        <div id="content-user" class="content" style="display: none;">
        	<iframe frameborder="no" border="0" width="100%" height="98%"></iframe>
        </div>
		<script type="text/javascript">
			/*
			 * 暴露接口
			 * 选择显示的模块
			 */
			function selectContent(name){
				$('#content-home').css({
					'display': 'none',
				});
				$('#content-text').css({
					'display': 'none',
				});
				$('#content-user').css({
					'display': 'none',
				});
				$('#content-'+name).css({
					'display': 'block',
				});
				$('#'+name).siblings().removeClass('selected');
				$('#'+name).addClass('selected');
			}
			/*
			 * 暴露接口
			 * text模块跳转至answerId的页面
			 */
			function setTextPage(answerId){
				wintq('加载中', 4, 0, 0, '');
				$('#content-text iframe').attr('src', "{:U('Text/index')}"+"?answerId="+answerId);
			}
			
			var isPC = {$isPC};
			var w_width, w_height;
			$(function() {
				var $page = {$page};
				var $imgauthor = {$imgauthor};
				var $words = {$words};

				/*
				 * setDomSize方法放在
				 * 后台根据isPC模版渲染的mainP.js或mainM.js里
				 */
				$(window).resize(setDomSize);
				setDomSize();
				
				//设置主页的展示内容
				$('#imgauthor').html($imgauthor);
				$('#words').html($words);
				var imgu = '../../../Public/image/one/' + $page + '.jpg';
				$('#img').css({
					"background-image": "url(" + imgu + ")"
				});

				//banner点击事件
				$('#home').click(function() {
					window.location.reload();
				});
				$('#text').click(function() {
					wintq('加载中', 4, 0, 0, '');
					selectContent('text');
					$('#content-text iframe').attr('src', "{:U('Text/index')}");
				});
				$('iframe').load(function() {
					delewintq();
				});
				$('#pool, #music').click(function() {
					$(this).text('>_<...');
				});
				$('#user').click(function(){
					//进入收藏界面
					wintq('加载中', 4, 0, 0, '');
					selectContent('user');
					$('#content-user iframe').attr('src', "{:U('User/index')}");
				});

				/*
				 * 如果cookie answerId被设置
				 * 说明登录之前请求收藏
				 * 在这里进行收藏及提示
				 */
				var answerId = getCookie('answerId');
				if (answerId) {
					$.ajax({
						type: 'post',
						url: "{:U('User/collect')}",
						data: 'answerId=' + answerId,
						success: function(data) {
							if (data == 'success') {
								console.log('收藏成功');
								delCookie('answerId');
								wintq('收藏成功', 1, 3*1000, 0, '');
							}
						},
						dataType: 'json',
						cache: false
					});
				}
				
				/*
				 * 如果cookie openid被设置
				 * 说明已登录
				 * banner右边展示用户信息
				 */
				var openid = getCookie('openid');
				if(openid){
					var nickname = getCookie('nickname');
					var figureurl = getCookie('figureurl');
					$('#user img').attr('src', figureurl);
					$('#user #nickname').text(nickname);
				}else{
					$('#user #nickname').text('登录');
					$('#user').click(function(){
						window.location.href = '/login.php';
					});
				}
				
			});
		</script>
	</body>

</html>